﻿import {
    Component,
    Injector,
    ViewChild,
    ViewEncapsulation,
    AfterViewInit
} from '@angular/core';
import { appModuleAnimation } from '@shared/animations/routerTransition';
import { AppComponentBase } from '@shared/common/app-component-base';
import {
    PipelineServiceProxy,
    PipelineListDto,
    PipelineNumDto
} from '@shared/service-proxies/service-proxies';
import { Paginator } from 'primeng/components/paginator/paginator';
import { LazyLoadEvent, MenuItem } from 'primeng/primeng';
import { Table } from 'primeng/table';
import { AppConsts } from '@shared/AppConsts';
@Component({
    templateUrl: './step.component.html',
    styleUrls: ['./step.component.less'],
    encapsulation: ViewEncapsulation.None,
    animations: [appModuleAnimation()]
})
export class StepsComponent extends AppComponentBase implements AfterViewInit {
    @ViewChild('dataTable') dataTable: Table;
    @ViewChild('paginator') paginator: Paginator;

    filterText = '';
    items: MenuItem[];
    type = 1;
    className1 = "active";
    className2 = "";
    className3 = "";
    status="";
    num = new PipelineNumDto();
    constructor(
        injector: Injector,

        private _pipelineService: PipelineServiceProxy
    ) {
        super(injector);
    }

    ngAfterViewInit(): void {
        this.getPipes();
       this.getNum();
    }
    getNum()
    {
        this._pipelineService.getNum().subscribe(result => {
            this.num = result;
        });
    }
    getPipes(event?: LazyLoadEvent) {
        if (this.primengTableHelper.shouldResetPaging(event)) {
            this.paginator.changePage(0);
            return;
        }

        this.primengTableHelper.showLoadingIndicator();
        console.log();
        this._pipelineService
            .getPipelines(
                this.filterText,
                this.type,
                '51',
                undefined,
                this.status,
                // undefined,
                // 10,
                this.primengTableHelper.getSorting(this.dataTable),
                this.primengTableHelper.getMaxResultCount(
                    this.paginator,
                    event
                ),
                this.primengTableHelper.getSkipCount(this.paginator, event)
            )
            .subscribe(result => {
                console.log(result.items);
                this.primengTableHelper.totalRecordsCount = result.totalCount;
                this.primengTableHelper.records = result.items;
                this.primengTableHelper.hideLoadingIndicator();
            });
    }

    pipelineRun(pipe: PipelineListDto) {
        this._pipelineService.getPipelineAndRun(pipe.id).subscribe(result => {
            this.notify.info('运行成功');
            this.getPipes();
            this.getNum();
        });
    }
    tabTypeClick(tab:number)
    {
        this.type = tab;
        if(tab==1)
        {
            this.className1="active";
            this.className2="";
            this.className3="";
        }
        else if(tab==2)
        {
            this.className1="";
            this.className2="active";
            this.className3="";
        }
        else if(tab==3)
        {
            this.className1="";
            this.className2="";
            this.className3="active";
        }
        this.getPipes();
    }
}
